# Contributor: Raed Rizqie <raed.rizqie@gmail.com>

_realname=maturin
pkgbase=mingw-w64-python-${_realname}
pkgname=${MINGW_PACKAGE_PREFIX}-python-${_realname}
pkgver=0.14.10
pkgrel=1
pkgdesc='Build and publish crates with pyo3, rust-cpython and cffi bindings as well as rust binaries as python packages (mingw-w64)'
url='https://github.com/pyo3/maturin'
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
license=('MIT')
depends=(
    ${MINGW_PACKAGE_PREFIX}-python
    ${MINGW_PACKAGE_PREFIX}-python-tomli)
makedepends=(
    ${MINGW_PACKAGE_PREFIX}-python-build
    ${MINGW_PACKAGE_PREFIX}-python-installer
    ${MINGW_PACKAGE_PREFIX}-python-wheel
    ${MINGW_PACKAGE_PREFIX}-python-setuptools-rust)
source=("${_realname}-${pkgver}.tar.gz::https://github.com/pyo3/${_realname}/archive/v${pkgver}.tar.gz"
        "001-fix-default-target-on-mingw-32bit.patch")
sha256sums=('8fc9bcdcb7f1535d5e3e8bb500c348ca1bff5a6dce87b0ab7dbc5a49723da28a'
            '5d363f2540f84651439f47782c9d60ababde58f7187b09945040f3795745bf45')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"

  patch -Np1 -i "${srcdir}/001-fix-default-target-on-mingw-32bit.patch"
}

build() {
  msg "Python build for ${MSYSTEM}"
  cp -r "${_realname}-${pkgver}" "python-build-${MSYSTEM}" && cd "python-build-${MSYSTEM}"

  ${MINGW_PREFIX}/bin/python -m build --wheel --skip-dependency-check --no-isolation
}

package() {
  cd "${srcdir}/python-build-${MSYSTEM}"

  MSYS2_ARG_CONV_EXCL="--prefix=" \
    ${MINGW_PREFIX}/bin/python -m installer --prefix=${MINGW_PREFIX} \
    --destdir="${pkgdir}" dist/*.whl

  install -Dm644 license-mit "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE"
}
